<template>
  <div class="info">
    <div v-if="showDialog" class="info-mask" @click="closeDialog()" />
    <el-card v-if="showBox" class="info-box" :style="{ right: showDialog ? 0 : -width + '%',width: width + '%' }">
      <slot name="header" />
      <slot name="content " />
      <el-button v-if="showDialog" type="primary" icon="el-icon-close" class="close" @click="closeDialog()" />
    </el-card>
  </div>
</template>

<script>
export default {
  name: 'Drawer',
  props: {
    showDialog: {
      type: Boolean,
      default: false
    },
    width: {
      type: Number,
      default: 50
    }
  },
  data () {
    return {
      showBox: false
    };
  },
  mounted () {
    // 隐藏切换延迟动画
    setTimeout(() => {
      this.showBox = true;
    }, 600);
  },
  methods: {
    closeDialog () {
      this.$emit('closeDialog');
    }
  }
};
</script>

<style scoped lang="scss">
.info {
  width: 100%;
  height: 100%;
  .info-mask {
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: rgba(0, 0, 0, 0.2);
  }
  .info-box {
    position: fixed;
    top: 60px;
    right: -500px;
    width: 500px;
    height: calc(100% - 60px);
    z-index: 21;
    overflow: visible;
    transition: right 0.4s ease;
    ::v-deep.el-card__body {
      padding: 0;
      height: 100%;
    }
    .close {
      position: absolute;
      top: 160px;
      left: -40px;
      width: 40px;
      height: 40px;
      box-sizing: border-box;
      padding: 0;
      border-radius: 4px 0 0 4px;
    }
  }
}
</style>
